<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>会员分组</title>
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/gh/bootcdn/BootCDN/ajax/libs/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="<%=path%>/hplus/css/style.min.css"/>
<link rel="stylesheet" type="text/css" href="<%=path%>/hplus/css/font-awesome.min93e3.css"/>
<link href="https://cdnjs.cloudflare.com/ajax/libs/jstree/3.3.4/themes/default/style.min.css" rel="stylesheet">
<style type="text/css">
body{font-size: 14px;padding-top: 10px;}
</style>
</head>
<body>
<div class="container-fluid">
	<div class="row">
		<div id="jsTree"></div>
	</div>
</div>
</body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/gh/bootcdn/BootCDN/ajax/libs/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jstree/3.3.4/jstree.min.js"></script>
<script type="text/javascript">
var path = "<%=path%>";
var groupId = getUrlParam("groupId");
var parentId = getUrlParam("parentId");

$(function(){
	init();
});

function init(){
	$.post(path+"/memberGroup/ajaxGroupTree",function(data){
		if(data.status != "200"){
			alert("远程请求出错");
			return ;
		}
		if($.jstree.reference('#jsTree') != null){
			$.jstree.reference('#jsTree').destroy();
		}
		var tree = "";
		tree += "<ul>";
		$.each(data.data,function(i,d){
			tree += "<li id='"+d.id+"' data-jstree='{\"type\":\"top\"}'>";
			tree += d.text;
			tree += "</li>";
		});
		tree += "</ul>";
		$("#jsTree").html(tree);
		
		$("#jsTree").jstree({
			core: {
		    	themes: {
					dots: false
				}
			},
			"types" : {
			    "default" : {
			      	"icon" : path+"/images/Artboard2.png"
			    },
			    "top" : {
			      	"icon" : path+"/images/Artboard.png"
			    }
			},
			"plugins" : [ "types","search" ]
		}).on("activate_node.jstree",function(e,data){
			var temp_groupId = data.node.id;
			if(parentId == temp_groupId){
				alert("已在当前分类");
				return ;
			}
			
			$.post(path+"/memberGroup/ajaxGroupMove",{id:groupId,parentId:temp_groupId},function(data){
				if(data.status == "200"){
					parent.init_tree();
					parent.selectGroupDialog.remove();
				}
			},"json");
		});
		
		$.jstree.reference('#jsTree').select_node(parentId);
	},"json");
}

function func_searchTree(){
	$("#jsTree").jstree(true).search($.trim($("#keyword").val()));
}

function getUrlParam(key){
	var reg = new RegExp("(^|&)"+ key +"=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg);
    if(r!=null)return  unescape(r[2]); return null;
}
</script>
</html>